﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;


namespace MolyMade.Moly.MailMessager.SmtpClient
{
    internal class BaseSmtp
    {
        public BaseSmtp(string host = null, int port =-1, string userName = null, string passWord = null, bool enableSsl = false)
        {
            if (host != null) this.Host = host;
            if (userName != null) this.UserName = userName;
            if (passWord != null) this.PassWord = passWord;
            this.Port = port;
            this.EnableSsl = enableSsl;
        }
        private System.Net.Mail.SmtpClient _smtpClient;
        public string Host { get; set; }
        public string UserName { get; set; }
        public string PassWord { get; set; }
        public int Port { get; set; }
        public bool EnableSsl { get; set; }
        public void Connect()
        {
            _smtpClient = this.Port != -1 ? new System.Net.Mail.SmtpClient(this.Host, this.Port) : new System.Net.Mail.SmtpClient(this.Host);
            _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            _smtpClient.Credentials = new NetworkCredential(this.UserName, this.PassWord);
            _smtpClient.EnableSsl = this.EnableSsl;
        }
        public void Send(BaseMessage mail)
        {
            _smtpClient.Send(mail.GetMessage());
        }
    }
}
